$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'watersub/dataerralertfixed/list',
        datatype: "json",
        colModel: [			
			{ label: 'opKey', name: 'opKey', index: 'op_key', width: 50, key: true },
			{ label: '${column.comments}', name: 'opAddDate', index: 'op_add_date', width: 80 }, 			
			{ label: '${column.comments}', name: 'deviceId', index: 'device_id', width: 80 }, 			
			{ label: '${column.comments}', name: 'nowDate', index: 'now_date', width: 80 }, 			
			{ label: '${column.comments}', name: 'nowData', index: 'now_data', width: 80 }, 			
			{ label: '${column.comments}', name: 'deviceStatus', index: 'device_status', width: 80 }, 			
			{ label: '${column.comments}', name: 'statusCode', index: 'status_code', width: 80 }, 			
			{ label: '${column.comments}', name: 'agoData', index: 'ago_data', width: 80 }, 			
			{ label: '${column.comments}', name: 'agoDeviceStatus', index: 'ago_device_status', width: 80 }, 			
			{ label: '${column.comments}', name: 'proName', index: 'pro_name', width: 80 }, 			
			{ label: '${column.comments}', name: 'deviceCount', index: 'device_count', width: 80 }, 			
			{ label: '${column.comments}', name: 'installerName', index: 'installer_name', width: 80 }, 			
			{ label: '${column.comments}', name: 'installerPhone', index: 'installer_phone', width: 80 }, 			
			{ label: '${column.comments}', name: 'debugerName', index: 'debuger_name', width: 80 }, 			
			{ label: '${column.comments}', name: 'debugerPhone', index: 'debuger_phone', width: 80 }, 			
			{ label: '${column.comments}', name: 'masterNum', index: 'master_num', width: 80 }, 			
			{ label: '${column.comments}', name: 'slaveNum', index: 'slave_num', width: 80 }, 			
			{ label: '${column.comments}', name: 'cardNum', index: 'card_num', width: 80 }, 			
			{ label: '${column.comments}', name: 'deviceArea', index: 'device_area', width: 80 }, 			
			{ label: '${column.comments}', name: 'deviceNei', index: 'device_nei', width: 80 }, 			
			{ label: '${column.comments}', name: 'deviceBuild', index: 'device_build', width: 80 }, 			
			{ label: '${column.comments}', name: 'deviceUnit', index: 'device_unit', width: 80 }, 			
			{ label: '${column.comments}', name: 'routeNum', index: 'route_num', width: 80 }, 			
			{ label: '${column.comments}', name: 'meterNum', index: 'meter_num', width: 80 }, 			
			{ label: '${column.comments}', name: 'deviceAddress', index: 'device_address', width: 80 }, 			
			{ label: '${column.comments}', name: 'deviceAddressCode', index: 'device_address_code', width: 80 }, 			
			{ label: '${column.comments}', name: 'clientId', index: 'client_id', width: 80 }, 			
			{ label: '${column.comments}', name: 'clientName', index: 'client_name', width: 80 }, 			
			{ label: '${column.comments}', name: 'clientSex', index: 'client_sex', width: 80 }, 			
			{ label: '${column.comments}', name: 'clientAge', index: 'client_age', width: 80 }, 			
			{ label: '${column.comments}', name: 'clientIdCard', index: 'client_id_card', width: 80 }, 			
			{ label: '${column.comments}', name: 'buildNum', index: 'build_num', width: 80 }, 			
			{ label: '${column.comments}', name: 'unitNum', index: 'unit_num', width: 80 }, 			
			{ label: '${column.comments}', name: 'houseNum', index: 'house_num', width: 80 }, 			
			{ label: '${column.comments}', name: 'cityName', index: 'city_name', width: 80 }, 			
			{ label: '${column.comments}', name: 'areaName', index: 'area_name', width: 80 }, 			
			{ label: '${column.comments}', name: 'cityId', index: 'city_id', width: 80 }, 			
			{ label: '${column.comments}', name: 'areaId', index: 'area_id', width: 80 }, 			
			{ label: '${column.comments}', name: 'unitIdG', index: 'unit_id_g', width: 80 }, 			
			{ label: '${column.comments}', name: 'unitNameG', index: 'unit_name_g', width: 80 }, 			
			{ label: '${column.comments}', name: 'unitIdW', index: 'unit_id_w', width: 80 }, 			
			{ label: '${column.comments}', name: 'unitNameW', index: 'unit_name_w', width: 80 }, 			
			{ label: '${column.comments}', name: 'delFlag', index: 'del_flag', width: 80 }, 			
			{ label: '${column.comments}', name: 'clientAddress', index: 'client_address', width: 80 }, 			
			{ label: '${column.comments}', name: 'typeCode', index: 'type_code', width: 80 }, 			
			{ label: '${column.comments}', name: 'typeName', index: 'type_name', width: 80 }, 			
			{ label: '${column.comments}', name: 'abnormal', index: 'abnormal', width: 80 }, 			
			{ label: '${column.comments}', name: 'proTypeId', index: 'pro_type_id', width: 80 }, 			
			{ label: '${column.comments}', name: 'modeName', index: 'mode_name', width: 80 }, 			
			{ label: '${column.comments}', name: 'deptId', index: 'dept_id', width: 80 }, 			
			{ label: '${column.comments}', name: 'unitId', index: 'unit_id', width: 80 }			
        ],
		viewrecords: true,
        height: $(window).height()-165,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		dataErrAlertFixed: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.dataErrAlertFixed = {};
		},
		update: function (event) {
			var opKey = getSelectedRow();
			if(opKey == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(opKey)
		},
		saveOrUpdate: function (event) {
		    $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function() {
                var url = vm.dataErrAlertFixed.opKey == null ? "watersub/dataerralertfixed/save" : "watersub/dataerralertfixed/update";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.dataErrAlertFixed),
                    success: function(r){
                        if(r.code === 0){
                             layer.msg("操作成功", {icon: 1});
                             vm.reload();
                             $('#btnSaveOrUpdate').button('reset');
                             $('#btnSaveOrUpdate').dequeue();
                        }else{
                            layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
			});
		},
		del: function (event) {
			var opKeys = getSelectedRows();
			if(opKeys == null){
				return ;
			}
			var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
               if(!lock) {
                    lock = true;
		            $.ajax({
                        type: "POST",
                        url: baseURL + "watersub/dataerralertfixed/delete",
                        contentType: "application/json",
                        data: JSON.stringify(opKeys),
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            }else{
                                layer.alert(r.msg);
                            }
                        }
				    });
			    }
             }, function(){
             });
		},
		getInfo: function(opKey){
			$.get(baseURL + "watersub/dataerralertfixed/info/"+opKey, function(r){
                vm.dataErrAlertFixed = r.dataErrAlertFixed;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});